/*{{entitySubName}}Service.js*/
'use strict';
app.factory('{{entitySubName}}Service', ['$http','OperationService','$q','activitiService',function($http,OperationService,$q,activitiService) {
	return {
		//通过参数查询
		queryMapByParams : function(params){
			return $http.post('/service2/{{entitySubName}}!queryMapByParams', params);
		},
		//通过参数分页查询
		queryPageByParams : function(params){
			return $http.post('/service2/{{entitySubName}}!queryPageByParams',params);
		},
		//通过参数查询实体列表
		queryByParams : function(params){
			return $http.post('/service2/{{entitySubName}}!queryByParams',params);
		},
		//保存或更新实体
		saveTemp : function(params){
			var defer = $q.defer();
			params.STATE = 'TEMP';
			OperationService.interAction({
                actionUrl: '/service2/{{entitySubName}}!saveOrUpdate',
                data: params,
                isSuccessBack: true,
                successTitle: '暂存成功',
                successFunc : function(data){
                	defer.resolve(data);
                }
            });
			return defer.promise;
		},
		saveOrUpdate : function(params){
			var defer = $q.defer();
			OperationService.interAction({
                actionUrl: '/service2/{{entitySubName}}!saveOrUpdate',
                data: params,
                isSuccessBack: true,
                successTitle: '保存成功',
                successFunc : function(data){
                	defer.resolve(data);
                }
            });
			return defer.promise;
		},
		//开启工作流
		startFlow:function(params){
			params.STATE='PAUTH';
			var defer = $q.defer();
			activitiService.activitiSubmit({
                    workKey: '{{tableName}}_WK',
                    actionUrl: '/service2/{{entitySubName}}!start',
                    data: params, 
                    successFunc : function(data){
                    	defer.resolve(data);
                    }   
            });	
			return defer.promise;
		},
		//根据id查询
		queryById : function(id){
			return $http.post('/service2/{{entitySubName}}!queryById',{ID:id});
		},
		//根据id删除
		deleteById : function(id){
			var defer = $q.defer();
			 OperationService.interAction({
                    actionUrl: '/service2/{{entitySubName}}!deleteById',
                    data: {ID:id},
                    isSuccessBack: true,
                 	confirmTitle: '确定删除？',
                    successTitle: '删除成功！',
                    successFunc : function(data){
                    	defer.resolve(data);
                    }
                });
			return defer.promise;
		}
	}
}]);
